package javaapplication1.view;

import java.util.List;
import java.util.Scanner;

import javaapplication1.control.BuyPetControl;
import javaapplication1.model.Pet;
import javaapplication1.dao.PetDao;
import javaapplication1.dao.oracleImpl.PetDaoOracleImpl;

public class BuyPetView {

	private static PetDao petDao = new PetDaoOracleImpl();
	private static BuyPetControl buyPetControl = new BuyPetControl();

	public static void buyPetView() {
		List<Pet> petList = null;
		if (SessionScope.getRole() == 1) {
			petList = petDao.retrievePetByOwnerId(0);
		} else if (SessionScope.getRole() == 2) {
			petList = petDao.retrievePetByStoreId(0);
		}
		System.out.println("******************************");
		System.out.println("宠物列表");
		for (int i = 0; i < petList.size(); i++) {
			System.out.print("序号：" + (i + 1));
			System.out.print("\t");
			System.out.print("名字：" + petList.get(i).getName());
			System.out.print("\t");
			System.out.print("品种：" + petList.get(i).getTypeName());
			System.out.print("\t");
			System.out.print("价格：" + petList.get(i).getPrice());
			System.out.println();
		}
		System.out.println("******************************");
		Scanner scanner = new Scanner(System.in);
		System.out.print("你的选择：");
		int choose = scanner.nextInt();
		if (choose > 0 && choose < petList.size() + 1) {
			buyPetControl.buyPetControl(petList.get(choose - 1));
		} else {
			System.out.println("输入有误，请重新输入");
			BuyPetView.buyPetView();
		}
	}

}